package com.cskaoyan.service;

import com.cskaoyan.bean.vo.*;
import com.cskaoyan.mapper.OrderGoodsMapper;
import com.cskaoyan.mapper.OrderMapper;
import com.cskaoyan.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class AdminStatServiceImpl implements AdminStatService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    OrderMapper orderMapper;
    @Autowired
    OrderGoodsMapper orderGoodsMapper;

    @Override
    public BaseStatisticsVO queryStatUser() {
        BaseStatisticsVO<StatUserVO> statUserVOBaseStatisticsVO = new BaseStatisticsVO<>();
        statUserVOBaseStatisticsVO.setColumns(new String[]{"day", "users"});
        List<StatUserVO> statUserVOList = userMapper.selectUserStatisticsByDay();
        statUserVOBaseStatisticsVO.setRows(statUserVOList);
        return statUserVOBaseStatisticsVO;
    }

    @Override
    public BaseStatisticsVO queryStatOrder() {
        BaseStatisticsVO<StatOrderVO> baseStatisticsVO = new BaseStatisticsVO();
        List<StatOrderVO> statOrderVOList = orderMapper.selectOrderStatisticsByDay();
        for (StatOrderVO orderStatisticsVO : statOrderVOList) {
            orderStatisticsVO.setPcr(orderStatisticsVO.getAmount() / orderStatisticsVO.getCustomers());
        }
        baseStatisticsVO.setColumns(new String[]{"day", "orders", "customers", "amount", "pcr"});
        baseStatisticsVO.setRows(statOrderVOList);
        return baseStatisticsVO;
    }

    @Override
    public BaseStatisticsVO queryStatGoods() {
        BaseStatisticsVO<StatGoodsVO> baseStatisticsVO = new BaseStatisticsVO();
        baseStatisticsVO.setColumns(new String[]{"day","orders","products","amount"});
        List<StatGoodsVO> statOrderVOS = orderGoodsMapper.selectOrderGoodsStatisticsByDay();
        baseStatisticsVO.setRows(statOrderVOS);
        return baseStatisticsVO;
    }
}
